package com.owg.jigsaw;

import javafx.scene.layout.Pane;

public class WWorkArea extends WPane
{
	
	public WWorkArea(WRoot root, Pane ui)
	{
		super(root, false, ui);
		if(ui != null)
			populateUI(ui);
	}
	public WWorkArea(WRoot root)
	{
		this(root, null);
	}
	
	@Override
	protected Pane makeUI()
	{
		Pane p = new Pane();
		populateUI(p);
		return p;
	}
	
	protected void populateUI(Pane p)
	{
		for(WBlock b : children)
		{
			p.getChildren().add(b.getUI());
		}
		children.addListener(referencer, (param, index, oldValue, newValue) -> 
		{
			if(oldValue != null)
				p.getChildren().remove(oldValue.getUI());
			if(newValue != null)
				p.getChildren().add(newValue.getUI());
		});
	}
	@Override
	public BlockDropAction accepts(WBlock b)
	{
		return BlockDropAction.ACCEPT;
	}
}
